﻿using mds.BaseFrameModel;
using mds.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.CMSService
{
    public class CMSProvider : ICMSProvider
    {
        private static CMSProvider _instance = new CMSProvider();

        public static CMSProvider Instance
        {
            get { return CMSProvider._instance; }

        }
        private CMSProvider() {
          
        }
        public OperationResult<string> ParseOutput(Dictionary<string, string> contentData, string template)
        {
            ArgumentHelper.AssertNotNullOrEmpty(template);
            return CMSCore.Instance.ParseOutput(contentData, template);
        }
        public List<PageTemplate> GetTemplatePageList(int currentPage, int pageSize, string searchKey, out int total)
        {
            ArgumentHelper.AssertInRange("currentPage", currentPage, 1, int.MaxValue);
            ArgumentHelper.AssertInRange("pageSize", pageSize, 1, int.MaxValue);
            return PageTemplateDao.GetPageList(currentPage,  pageSize,  searchKey, out  total);
        }

        public  string GetTemplateById(int templateId)
        {
            ArgumentHelper.AssertInRange("pageSize", templateId, 1, int.MaxValue);
            return PageTemplateDao.GetTemplateById(templateId);
        }
        /// <summary>
        /// 操作成功返回信息id，失败返回0
        /// </summary>
        /// <param name="pageTemplateId"></param>
        /// <param name="templateName"></param>
        /// <param name="templateContent"></param>
        /// <param name="createBy"></param>
        /// <param name="modifyBy"></param>
        /// <returns>信息id</returns>
        public  int PageTemplateUpdate(int pageTemplateId, string templateName, string templateContent, int templateType, int createBy, int modifyBy)
        {
            ArgumentHelper.AssertInRange("pageTemplateId", pageTemplateId, 1, int.MaxValue);
            ArgumentHelper.AssertInRange("createBy", createBy, 1, int.MaxValue);
            ArgumentHelper.AssertNotNullOrEmpty(templateName, templateContent);
            return PageTemplateDao.PageTemplateUpdate(pageTemplateId,  templateName,  templateContent,  templateType,  createBy,  modifyBy);
        }

        public  bool DeleteInfos(int[] templateIds, int operationBy)
        {
            ArgumentHelper.AssertNotNull<int[]>(templateIds);
            ArgumentHelper.AssertInRange("operationBy", operationBy, 1, int.MaxValue);
            return PageTemplateDao.DeleteInfos(templateIds, operationBy);
        }
    }
}
